#ifndef _PACKETMGR_H
#define _PACKETMGR_H

#include <QThread>
#include <set>
#include "qqdef.hpp"
#include "loop.hpp"

#include "qqpacket.hpp"
class qqclient;
typedef struct qqpacketmgr{
	int 		recv_packets;
	int 		failed_packets;
	QThread* 	thread_recv;
	
	loop		ready_loop;//待发送的包
	loop		temp_loop; //recv线程的ready_loop
	loop		sent_loop;//需要被ack的包
	
//	ushort		seqno[MAX_COMMAND];
	QMutex		recv_loop_lock;
	typedef std::set<uint> recv_loop_type;
	recv_loop_type		recv_loop;
}qqpacketmgr;


qqpacket* packetmgr_new_send( qqclient* qq, int cmd );
void packetmgr_del_packet( qqpacketmgr* mgr, qqpacket* p );
ushort packetmgr_inc_seqno( qqclient* qq );
void packetmgr_new_seqno( qqclient* qq );

int packetmgr_put_urge( qqclient* qq, qqpacket* p, bool urge );
int packetmgr_start( qqclient* qq );
void packetmgr_end( qqclient* qq );

#endif
